<template>
	<view class="page" :style="themeColor">

		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
			<view class='flex flex-direction flex-wrap align-center login_fd0_0'>
				<image class='login_fd0_0_c0' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
			</view>
			<view class='flex flex-wrap align-center login_fd0_1'>
				<image class='login_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
				<input class='flex-sub login_fd0_1_c1' type="number" placeholder="请输入手机号" confirm-type="done"
					:maxlength="11" placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx"
					v-model="account" />
			</view>
			<view class='flex flex-wrap align-center login_fd0_2'>
				<image class='login_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"4.png"'></image>
				<benben-flex-password-diy v-model="password" class-name="flex align-center flex-sub flex login_fd0_2_c1"
					:placeholder="'请输入密码(6~12位字母+数字)'" :maxlength="12" :default-type='true'
					placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx">
					<template #show>
						<text class='fu-iconfont2  login_fd0_2_c1_icon1' data-type="show">&#xE837;</text>
					</template>
					<template #hide>
						<text class='fu-iconfont2  login_fd0_2_c1_icon1' data-type="hide">&#xEBCC;</text>
					</template>
				</benben-flex-password-diy>
			</view>
			<text class='self-end login_fd0_3' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dlzc/codeLogin/codeLogin`">验证码登录</text>
			<view class='flex align-center justify-center'>
				<button class='login_fd0_4_c0' @tap.stop="goLoginFunc()">登录</button>
			</view>
			<view class='flex flex-wrap align-center justify-center login_fd0_5'>
				<text class='login_fd0_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/register/register`">注册账号 </text>
				<view class='flex flex-wrap align-center login_fd0_5_c1'>
				</view>
				<text class='login_fd0_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/forgetPwd/forgetPwd`">忘记密码</text>
			</view>
		</view>


		<view class="flex flex-direction align-center benben-position-layout flex login_flex_1" v-if="is_hide == 0">
			<view class='flex flex-wrap align-center'>
				<view class='flex flex-wrap align-center login_fd1_0_c0'>
				</view>
				<text class='login_fd1_0_c1'>快捷登录</text>
				<view class='flex flex-wrap align-center login_fd1_0_c0'>
				</view>
			</view>
			<image class='login_fd1_1' :src='STATIC_URL+"73.png"' @tap.stop="wxLogin"></image>

		</view>
		<view :style="{height: '300rpx'}"></view>


	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"account": "",
				"password": "",
				"userInfo": {
					"user_token": "",
					"id": "",
					"avatar": "",
					"real_name": "",
					"nickname": "",
					"gender": "",
					"mobile": "",
					"birthday": "",
					"phone": "",
					"email": "",
					"client_id": ""
				},
				"check": false,
				"is_hide": 1  // 0不隐藏  1隐藏
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.isHideWeixin();
			} else {
				this.is_hide = 0;
			}
			
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 隐藏三方登录  post64e55d065a945
			isHideWeixin() {
				this.$api.post(global.apiUrls.post64e55d065a945, {
					code: 'sides_config'
				}).then(res => {
					if (res.data.code == 1) {
						this.is_hide = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			
			
			
			//登录
			async goLoginFunc() {
				if (!validate(this.account, 'require')) {
					this.$message.info('手机号不能为空');
					return false;
				}
				if (!validate(this.account, 'phone')) {
					this.$message.info('请输入正确的手机号');
					return false;
				}
				if (!validate(this.password, 'require')) {
					this.$message.info('密码不能为空');
					return false;
				}
				if (!validate(this.password, 'password')) {
					this.$message.info('请输入6-12位字母+数字密码');
					return false;
				}
				// if (this.check === false) {
				// 	this.$message.info('请阅读并同意用户注册协议和隐私政策');
				// 	return false;
				// }
				//请求方法
				//数据验证

				let datauserInfo = await this.$api.post(global.apiUrls.post5c78dbfd977cf, {
					account: this.account,
					password: this.password,
					account_type: 'mobile'
				});

				if (datauserInfo.data.code != 1) {
					this.$message.info(datauserInfo.data.msg);
					return
				}
				this.$message.info(datauserInfo.data.msg);
				let infouserInfo = datauserInfo.data;
				this.userInfo = infouserInfo.data.userinfo;
				this.$store.commit('saveToken', this.userInfo.user_token);
				this.$store.commit('updateUserInfo', this.userInfo);
				if (this.userInfo.audit_status == 2) {
					setTimeout(()=> {
						uni.navigateTo({
							url: '/pages/dlzc/next/next?type=2'
						})
					}, 800)
				} else if (this.userInfo.audit_status == 1) {
					setTimeout(() => {
						this.toHomeDiy();
					}, 800)
				} else if (this.userInfo.audit_status == -1) {
					setTimeout(()=> {
						uni.navigateTo({
							url: '/pages/dlzc/next/next?type=1'
						})
					}, 800)
				}
				
			},
			
			/**
			 * @event 微信登陆
			 */
			wxLogin() {
				let _this = this;
				// if (!this.is_tick) return this.$message.info('请阅读并同意用户注册协议与隐私政策');
				// #ifdef APP-PLUS
				// 如果是app环境打开微信
				if (
					plus.runtime.isApplicationExist({
						pname: "com.tencent.mm",
						action: "weixin://",
					})
				) {
					uni.getProvider({
						service: "oauth",
						success: function(res) {
							console.log(res);
							// 如果支持微信等，就执行 wx_login_fn 方法
							if (~res.provider.indexOf("weixin")) {
								_this.wx_login_fn();
							}
						},
						fail: function(err) {
							// api错误是打印错误
							console.log(err);
						},
					});
				} else {
					// 调起失败时提醒用户
					this.$message.info("请安装微信后再使用此功能");
				}
				// #endif
			},
			/**
			 * @function 微信授权登录
			 */
			wx_login_fn() {
				let _this = this;
				/**
				 * @desc uniapp的登陆api
				 * @param {String} provider - 登录服务提供商
				 * @param {login~success} loginRes - 接口调用成功时的回调函数
				 */
				uni.login({
					provider: "weixin",
					// onlyAuthorize: true, // 微信登录仅请求授权认证
					/**
					 * @callback login~success
					 * @param {Object} loginRes - api返回来的信息
					 */
					success: function(loginRes) {
						console.log(loginRes);
						/**
						 * @desc 获取用户信息
						 * @param {String} provider - 登录服务提供商
						 * @param {Funtion} success - 接口调用成功时的回调函数
						 */
						uni.getUserInfo({
							provider: "weixin",
							success: function(infoRes) {
								// 显示加载状态
								uni.showLoading({
									title: '加载中...',
								});

								/**
								 * @description 第三方登录请求接口
								 */
								let extend_info = {
									openid: infoRes.userInfo.openId,
									unionid:infoRes.userInfo.unionId
								};
								_this.$api.post(global.apiUrls.post5d7660a421e69, {
										third_type: 'wx_app',
										extend_info: JSON.stringify(extend_info)
									})
									.then((res) => {
										console.log(res);
										// 保存用户信息
										// 关闭加载效果
										uni.hideLoading();
										if (res.data.code == 1) {
											_this.$message.info(res.data.msg);
											/**
											 * @description 向Vux发送用户信息保存
											 * @param {String} updateUserInfo - 调用的方法名称
											 * @param {Object} res.data.data.userinfo - 用户信息
											 */
											_this.userInfo = res.data.data.userinfo;
											_this.$store.commit('updateUserInfo', _this.userInfo)
											_this.$store.commit('saveToken', _this.userInfo.user_token)
											
											if (_this.userInfo.audit_status == 2) {
												setTimeout(()=> {
													uni.navigateTo({
														url: '/pages/dlzc/next/next?type=2'
													})
												}, 800)
											} else if (_this.userInfo.audit_status == 1) {
												
												setTimeout(() => {
													_this.toHomeDiy();
												}, 800)
											} else if (_this.userInfo.audit_status == -1) {
												setTimeout(()=> {
													uni.navigateTo({
														url: '/pages/dlzc/next/next?type=1'
													})
												}, 800)
											}
										} else if (res.data.code == -999) {
											/**
											 * @description 清除当前页面，跳转到绑定手机页面
											 */
											_this.$message.info(res.data.msg);
											setTimeout(() => {
												uni.navigateTo({
													url: '/pages/dlzc/bandMobile/bandMobile?extend_info=' + JSON.stringify(extend_info)
												})
											}, 800)
										} else {
											_this.$message.info(res.data.msg);
											return;
										}
									})
									.catch((err) => {
										uni.hideLoading();
										console.log(err);
									});
									console.log(infoRes.userInfo.unionId, "app微信登录");
			
							},
							fail: function(err) {
								uni.hideLoading();
								console.log(err);
							}
						});
					},
					fail: function(err) {
						uni.hideLoading();
						console.log(err);
					},
				});
			},
			
			//土司显示
			tusiShowFunc() {
				this.$message.info('该账户正在审核中~');
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(255, 255, 255, 1);
		background-size: 100% auto !important;
	}

	.login_fd0_5_c1 {
		background: rgba(191, 191, 191, 1);
		width: 1rpx;
		height: 24rpx;
		background-size: 100% auto !important;
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.login_fd0_5_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		line-height: 40rpx;
	}

	.login_fd0_5 {
		line-height: 40rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.login_fd0_4_c0 {
		background: rgba(205, 150, 45, 1);
		font-size: 32rpx;
		color: #fff;
		height: 88rpx;
		line-height: 88rpx;
		font-weight: 500;
		width: 638rpx;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
	}

	.login_fd0_3 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 32rpx 55rpx 48rpx 0rpx;
	}

	.login_fd0_2_c1_icon1 {
		width: 88rpx;
		line-height: 88rpx;
		text-align: center;
		font-size: 40rpx;
	}

	::v-deep .login_fd0_2_c1 {
		padding: 0rpx 0rpx 0rpx 0rpx;
		height: 125rpx;
		width: 620rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
	}

	.login_fd0_2 {
		border-bottom: 1px solid #eee;
		margin: 0rpx 36rpx 0rpx 28rpx;
	}

	.login_fd0_1_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
	}

	.login_fd0_1_c0 {
		width: 34rpx;
		height: 34rpx;
		margin: 0rpx 28rpx 0rpx 0rpx;
	}

	.login_fd0_1 {
		border-bottom: 1px solid #eee;
		padding: 40rpx 0rpx 40rpx 0rpx;
		margin: -191rpx 36rpx 0rpx 28rpx;
	}

	.login_fd0_0_c0 {
		width: 296rpx;
		height: 82rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 222rpx 0rpx 0rpx 0rpx;
	}

	.login_fd0_0 {
		background: url(/static/images/1.png) no-repeat, transparent;
		height: 600rpx;
		background-size: 100% auto !important;
	}

	.login_flex_1 {
		background: #fff;
		width: 750rpx;
		height: 300rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.login_fd1_1 {
		width: 80rpx;
		height: 80rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.login_fd1_0_c1 {
		line-height: 32rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #999999;
		padding: 0rpx 7rpx 0rpx 7rpx;
	}

	.login_fd1_0_c0 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}
</style>